<?php
	class dbExame extends db{		
		public $tabela = 'exame';
		
		public function __construct(){
			parent::__construct();
		}		
		
		public function inserirExame($exame){			
			
			if($exame->cod_exame){
				$pre = $this->db->prepare("UPDATE `{$this->tabela}` SET nome=?,descricao=? WHERE cod_exame =?");
				$pre->bindParam(1, $exame->nome,PDO::PARAM_STR);
				$pre->bindParam(2, $exame->descricao,PDO::PARAM_STR);
				$pre->bindParam(3, $exame->cod_exame,PDO::PARAM_STR);
				$pre->execute();				
			}else{
				$pre = $this->db->prepare("INSERT INTO `{$this->tabela}` VALUES (null,?,?)");
				$pre->bindParam(1, $exame->nome,PDO::PARAM_STR);
				$pre->bindParam(2, $exame->descricao,PDO::PARAM_STR);
				$pre->execute();
			}
			return $this->listarTodosExames();
		}
		public function listarTodosExames(){
			$retorno = $this->db->query("SELECT * FROM `{$this->tabela}`");
			$retorno->setFetchMode(PDO::FETCH_OBJ);
			return $retorno->fetchAll();
		}
		public function listarExames($nomeExame){
			$retorno = $this->db->query("SELECT * FROM `{$this->tabela}` WHERE nome LIKE '%".$nomeExame."%'");
			$retorno->setFetchMode(PDO::FETCH_OBJ);
			return $retorno->fetchAll();
		}
		
		
	}